<?php

namespace API\App\Action;

use Hx\App;
use Hx\Request;
use Hx\Event;

class Comment {

    public function __construct(){
        Event::trigger('token-validate');
    }

    public function getList() {
        $page = Request::get('page');
        $page = $page > 1 ? $page : 1;
        $data = App::Model('Comment->getList', array('1=1', $page));
        return !$data ? array('error' => true, 'msg' => '查询失败') : $data;
    }

    public function getTree($node) {
        $data = App::Model('Comment->getTree', array((int)$node));
        return !$data ? array('error' => true, 'msg' => '查询失败') : array('comment' => $data);
    }

    public function getOne($id) {
        $data = App::Model('Comment->getOne', array((int)$id));
        return !$data ? array('error' => true, 'msg' => '查询失败') : array('comment' => $data);
    }

    public function getPrivates() {
        $page = Request::get('page');
        $page = $page > 1 ? $page : 1;
        $data = App::Model('Comment->getList', array('status != "public"', $page));
        return !$data ? array('error' => true, 'msg' => '查询失败') : $data;
    }
}